#!/bin/bash

DJANGO_VERSION=1.4.2

# rpm –import https://fedoraproject.org/static/0608B895.txt
# rpm -ivh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch.rpm
if [ "$(uname -m)" = "x86_64" ]
then
  rpm -Uhv http://ftp-stud.fht-esslingen.de/dag/redhat/el6/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
else
  rpm -Uhv http://ftp-stud.fht-esslingen.de/dag/redhat/el6/en/i386/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
fi

yum -y upgrade

cd /usr/src

# Installation des dépendances et de Python 2.7 avec threads et librairies partagées
yum install -y sqlite sqlite-devel gcc gdbm-devel readline-devel ncurses-devel zlib-devel bzip2-devel sqlite-devel db4-devel openssl-devel tk-devel bluez-libs-devel wget make
wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
tar xvjf Python-2.7.3.tar.bz2
pushd Python-2.7.3
./configure --with-threads --enable-shared
make && make altinstall
cat > /etc/ld.so.conf.d/opt-python2.7.conf << EOF
/usr/local/lib
EOF
ldconfig
if [[ ! -a /root/.bashrc ]]
then
    touch /root/.bashrc
fi
echo "alias python=$(which python2.7)" >> /root/.bashrc
. /root/.bashrc
popd

# Installer apache2, mod_wsgi et mod_x_sendfile
yum install -y httpd{,-devel}
wget http://modwsgi.googlecode.com/files/mod_wsgi-3.4.tar.gz
tar xvzf mod_wsgi-3.4.tar.gz
pushd mod_wsgi-3.4/
./configure --with-python=/usr/local/bin/python2.7
make && make install
if [ "$(uname -m)" = "x86_64" ]
then
    lib_path="lib64"
else
    lib_path="lib"
fi
echo "LoadModule wsgi_module /usr/$lib_path/httpd/modules/mod_wsgi.so" > /etc/httpd/conf.d/mod_wsgi.conf
service httpd restart
popd

# Installation de Django
wget http://www.djangoproject.com/download/$DJANGO_VERSION/tarball/
tar xvzf Django-$DJANGO_VERSION.tar.gz
pushd Django-$DJANGO_VERSION
python2.7 setup.py install
popd

# Installation de docutils
wget "http://docutils.svn.sourceforge.net/viewvc/docutils/trunk/docutils/?view=tar" -O docutils-snapshot.tgz
tar xvzf docutils-snapshot.tgz
pushd docutils
python2.7 setup.py install
popd

# Installation de mod_xsendfile
wget --no-check-certificate https://tn123.org/mod_xsendfile/mod_xsendfile.c
apxs -cia mod_xsendfile.c
if [ ! -e /usr/local/django ] 
then
        mkdir -p -v /usr/local/django
else
        echo "/usr/local/django already exists"
fi
echo "XSendFile on
XSendFilePath /usr/local/django" > /etc/httpd/conf.d/mod_xsendfile.conf
service httpd restart

cd
